import { Schema } from "@hapi/joi";
import { NextFunction, Request, Response } from "express";
import { CustomResponse } from "./error";
/**
 * 数据验证中间件
 * @param schema 验证规则
 * @returns 
 */
export const validate = (schema: Schema) => {
  return (req: Request, res: CustomResponse, next: NextFunction) => {
    const { error } = schema.validate(req.body);
    console.log(error)
    if (error) {
      return res.cc(error.details[0].message);
    }
    next();
  }
}
